<template>
	<div>
		<InputOutputDefine
			:versionId="props.id"
			:stepCode="props.nodeId"
			:topFlag="false"
			:resource="props.frontFile"
			:outputFlag="true"
			:inputFlag="false"
		>
		</InputOutputDefine>

		<a-row>
			<a-col span="24">
				<div style="height: 500px; overflow: scroll">
					<a-row v-if="props.componentConfig?.config" v-for="item in props.componentConfig.config.output">
						<a-col span="24">
							<a-row>
								<a-col span="6"> <a-input v-model:value="item.newFromTransformName"></a-input></a-col>
								<a-col span="6">
									<a-tag>{{ item.fromTransformName }}</a-tag>
								</a-col>
							</a-row>
						</a-col>
						<a-col span="24">
							<ParamDefine
								:params="item.outputDefine"
								:isViewBasicFieldFlag="false"
								:isViewArrayFlag="true"
								:isAddColumnFlag="false"
								:isActionColumnFlag="false"
								:isUpdateColumnFlag="false"
								:jsonEditorFlag="false"
								:defaultValueFlag="false"
								:isRemoveColumnFlag="false"
								:isAddChildrenColumnFlag="false"
								:isMappingColumnFlag="false"
								ref="left"
							></ParamDefine>
						</a-col>
					</a-row>
				</div>
			</a-col>
		</a-row>
	</div>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import ParamDefine from '@/views/restapi/ParamDefine.vue'
import processVersionContentApi from '@/api/process/processVersionContentApi'
import { hasProperties } from '@/utils'

const props = defineProps(['componentConfig', 'nodeId', 'id', 'frontFile'])

// const isArrayFlag = ref(false);
const left = ref()

const defaultConfig = () => {
	return {
		config: {
			output: []
		}
	}
}

onMounted(async () => {
	if (!hasProperties(props.componentConfig)) {
		const c = defaultConfig()
		props.componentConfig.config = c.config
	}

	const group = await getCurrentInputDefineGroup()
	mergeValue(group)
	props.componentConfig.config.output = group
})

const mergeValue = (group) => {
	for (let out of group) {
		let g = findOutDefine(out.fromTransformName)
		if (g) {
			out.newFromTransformName = g.newFromTransformName
			out.outputDefine.isArrayFlag = g.outputDefine.isArrayFlag
		}
	}
}
const findOutDefine = (fromTransformName) => {
	let result = null
	for (let g of props.componentConfig.config.output) {
		if (g.fromTransformName == fromTransformName) {
			result = g
		}
	}
	return result
}

const getCurrentInputDefineGroup = async () => {
	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentInputDefineGroup({
		id: props.id,
		frontFile: props.frontFile,
		stepCode: props.nodeId
	})

	for (const c of read) {
		c.newFromTransformName = c.newFromTransformName || c.fromTransformName
	}
	return read
}
</script>
<style scoped></style>
